//
//  SearchTableViewCell.m
//  Boom
//
//  Created by 云鹏 赵 on 15/3/13.
//  Copyright (c) 2015年 lanou3g. All rights reserved.
//

#import "SearchTableViewCell.h"

@implementation SearchTableViewCell
- (void)dealloc
{
    [_searchAlbum release];
    [_backgroundLable release];
    [_myImageView release];
    [_titleLable release];
    [_category_title release];
    [_tagsLable release];
    [_playLable release];
    [super dealloc];
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self creatCell];
    }
    return self;
}
- (void)creatCell
{
    self.backgroundColor = [UIColor colorWithRed:244 / 255.0 green:244 / 255.0 blue:244 / 255.0 alpha:1];
    // 创建背景backgroundLable
    self.backgroundLable = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 375, 115)];
    self.backgroundLable.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.backgroundLable];
    [_backgroundLable release];

    
    // 创建图片imageView;
    self.myImageView = [[UIImageView alloc] initWithFrame:CGRectMake(15, 12.5, 100, 100)];
    self.myImageView.backgroundColor = [UIColor cyanColor];
    self.myImageView.layer.masksToBounds = YES;
    // 2. 设置图片圆角
    self.myImageView.layer.cornerRadius = 50;
    // 3. 设置边框宽度
    self.myImageView.layer.borderWidth = 0.5;
    // 4. 设置边框颜色
    self.myImageView.layer.borderColor = [UIColor whiteColor].CGColor;
    [self addSubview:self.myImageView];
    [_myImageView release];
    
    // 创建标题titleLable
    self.titleLable = [[UILabel alloc] initWithFrame:CGRectMake(self.myImageView.frame.origin.x + self.myImageView.frame.size.width + 10, self.myImageView.frame.origin.y, self.backgroundLable.frame.size.width - 15 - self.myImageView.frame.size.width - 15 - 10, 30)];
    self.titleLable.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.titleLable];
    [_titleLable release];
    
    // 创建标签lable
    self.tagsLable = [[UILabel alloc] initWithFrame:CGRectMake(self.titleLable.frame.origin.x, self.titleLable.frame.origin.y + self.titleLable.frame.size.height + 5, self.titleLable.frame.size.width, self.titleLable.frame.size.height)];
    self.tagsLable.backgroundColor = [UIColor whiteColor];
    self.tagsLable.textColor = [UIColor blackColor];
    self.tagsLable.font = [UIFont systemFontOfSize:14.0];
    [self addSubview:self.tagsLable];
    [_tagsLable release];
    
    // 类别lable
    self.category_title = [[UILabel alloc] initWithFrame:CGRectMake(self.tagsLable.frame.origin.x, self.tagsLable.frame.origin.y + self.tagsLable.frame.size.height + 5, self.tagsLable.frame.size.width / 2 - 30, 30)];
    self.category_title.textColor = [UIColor grayColor];
    self.category_title.backgroundColor = [UIColor whiteColor];
    self.category_title.font = [UIFont systemFontOfSize:12.0];
    [self addSubview:self.category_title];
    [_category_title release];
    
    // 播放次数
    self.playLable = [[UILabel alloc] initWithFrame:CGRectMake(self.category_title.frame.origin.x + self.category_title.frame.size.width + 5, self.category_title.frame.origin.y, self.category_title.frame.size.width + 5, self.category_title.frame.size.height)];
    self.playLable.textColor = [UIColor grayColor];
    self.playLable.backgroundColor = [UIColor whiteColor];
    self.playLable.font = [UIFont systemFontOfSize:12.0];
    [self addSubview:self.playLable];
    [_playLable release];

    
}

// 重写set
- (void)setSearchAlbum:(SearchAlbum *)searchAlbum
{
    if (_searchAlbum != searchAlbum) {
        [_searchAlbum release];
        _searchAlbum = [searchAlbum retain];
    }
    // 下载图片
    NSString *string = _searchAlbum.cover_path;
    NSURL *url = [NSURL URLWithString:string];
    [self.myImageView sd_setImageWithURL:url placeholderImage:nil];
    
    self.titleLable.text = _searchAlbum.title;
    self.category_title.text = [NSString stringWithFormat:@"类别:%@", _searchAlbum.category_title];
    self.playLable.text = [NSString stringWithFormat:@"播放次数:%ld", (long)_searchAlbum.play];
    self.tagsLable.text = _searchAlbum.tags;
    
}



- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
